class Admin::ShopTypesController < AdminController
  def index
    @shop_types = ShopType.page(params[:page]).per(params[:per])
  end

  def new
    @shop_type = ShopType.new
  end

  def create
    @shop_type = ShopType.new shop_type_params
    if @shop_type.save
      redirect_to admin_shop_types_path, notice: "保存成功！"
    else
      redirect_to admin_shop_types_path, notice: "保存失败！"
    end
  end

  def edit
    @shop_type = ShopType.find params[:id]
  end

  def update
    @shop_type = ShopType.find params[:id]
    if @shop_type.update shop_type_params
      redirect_to admin_shop_types_path, notice: "更新成功！"
    else
      redirect_to admin_shop_types_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @shop_type = ShopType.find params[:id]
    if @shop_type.destroy
      redirect_to admin_shop_types_path, notice: "删除成功."
    else
      redirect_to admin_shop_types_path, notice: "删除失败."
    end
  end

  private

  def shop_type_params
    params.require(:shop_type).permit(:name)
  end
end
